package jsu.blogger.service.impl;

import jsu.blogger.mapper.PostMapper;
import jsu.blogger.mapper.UsersMapper;
import jsu.blogger.pojo.Post;
import jsu.blogger.pojo.Users;
import jsu.blogger.service.inter.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SearchServiceImpl implements SearchService {
    @Autowired
    private PostMapper postMapper;
    @Autowired
    private UsersMapper usersMapper;
    @Override
    public List<Post> searchPostPage(String searchContent, int currentPage, int pageSize) {
        int begin=currentPage*pageSize;
        List<Post> result=postMapper.selectPostListPageBySearchContent(searchContent,begin,pageSize);
        return result;
    }

    @Override
    public List<Users> searchUserPage(String searchContent, int currentPage, int pageSize) {
        int begin=currentPage*pageSize;
        List<Users> result=usersMapper.selectUserPageBySearchContent(searchContent,begin,pageSize);
        if(result!=null){
            for (Users user:
                 result) {
                user.setCurrentDevice("oppo a5");
                user.setPassword("******");
            }
        }
        return result;
    }
}
